<?php


namespace app\api\library\index\getUserAddress;


use think\facade\Db;

class V
{
    public static function run($param)
    {
        $userId = _checkEmptyParam($param[ 'userId' ], '用户ID不能为空');
        //查询用户的所有地址
        $where   = [
            ['user_id', '=', $userId],
            ['delete_time', '=', null],
        ];
        $total   = Db::name('mall_address')
            ->where($where)
            ->count();
        $address = Db::name('mall_address')
            ->where($where)
            ->order(['current' => 'desc','id' => 'desc'])
            ->field('id,name,phone,province_id,province,city_id,city,region_id,region,detail,current')
            ->select()->toArray();
        $res = [
            'total' => $total,
            'list'  => $address,
        ];
        _outPut(200, $res);
    }
}